def singleton(cls):
    instances = {}
    def getInstance():
        if cls not in instances:
            instances[cls] = cls()
            return instances[cls]
        return getInstance()

@singleton
class MyClass:
    pass
